home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 13 / Engine / Engine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-20  |  5.8 KB  |  161 lines

  1. //-----------------------------------------------------------------------------
  2. // The primary engine header file. This file links the entire engine together
  3. // and is the only header file that needs to be included in any project using
  4. // the engine.
  5. //
  6. // Programming a Multiplayer First Person Shooter in DirectX
  7. // Copyright (c) 2004 Vaughan Young
  8. //-----------------------------------------------------------------------------
  9. #ifndef ENGINE_H
  10. #define ENGINE_H
  11.  
  12. //-----------------------------------------------------------------------------
  13. // DirectInput Version Define
  14. //-----------------------------------------------------------------------------
  15. #define DIRECTINPUT_VERSION 0x0800
  16.  
  17. //-----------------------------------------------------------------------------
  18. // System Includes
  19. //-----------------------------------------------------------------------------
  20. #include <stdio.h>
  21. #include <tchar.h>
  22. #include <windowsx.h>
  23.  
  24. //-----------------------------------------------------------------------------
  25. // DirectX Includes
  26. //-----------------------------------------------------------------------------
  27. #include <d3dx9.h>
  28. #include <dinput.h>
  29. #include <dplay8.h>
  30. #include <dmusici.h>
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Macros
  34. //-----------------------------------------------------------------------------
  35. #define SAFE_DELETE( p )       { if( p ) { delete ( p );     ( p ) = NULL; } }
  36. #define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p );   ( p ) = NULL; } }
  37. #define SAFE_RELEASE( p )      { if( p ) { ( p )->Release(); ( p ) = NULL; } }
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Engine Includes
  41. //-----------------------------------------------------------------------------
  42. #include "Resource.h"
  43. #include "LinkedList.h"
  44. #include "ResourceManagement.h"
  45. #include "Geometry.h"
  46. #include "Font.h"
  47. #include "Scripting.h"
  48. #include "DeviceEnumeration.h"
  49. #include "Input.h"
  50. #include "Network.h"
  51. #include "SoundSystem.h"
  52. #include "BoundingVolume.h"
  53. #include "Material.h"
  54. #include "Mesh.h"
  55. #include "SceneObject.h"
  56. #include "AnimatedObject.h"
  57. #include "SpawnerObject.h"
  58. #include "ViewFrustum.h"
  59. #include "RenderCache.h"
  60. #include "SceneManager.h"
  61. #include "CollisionDetection.h"
  62. #include "State.h"
  63.  
  64. //-----------------------------------------------------------------------------
  65. // Engine Setup Structure
  66. //-----------------------------------------------------------------------------
  67. struct EngineSetup
  68. {
  69.     HINSTANCE instance; // Application instance handle.
  70.     GUID guid; // Application GUID.
  71.     char *name; // Name of the application.
  72.     float scale; // Unit scale in meters/unit.
  73.     unsigned char totalBackBuffers; // Number of back buffers to use.
  74.     void (*HandleNetworkMessage)( ReceivedMessage *msg ); // Network message handler.
  75.     void (*StateSetup)(); // State setup function.
  76.     void (*CreateMaterialResource)( Material **resource, char *name, char *path ); // Material resource creation function.
  77.     char *spawnerPath; // Path for locating the spawner object scripts.
  78.  
  79.     //-------------------------------------------------------------------------
  80.     // The engine setup structure constructor.
  81.     //-------------------------------------------------------------------------
  82.     EngineSetup()
  83.     {
  84.         GUID defaultGUID = { 0x24215591, 0x24c0, 0x4316, { 0xb5, 0xb2, 0x67, 0x98, 0x2c, 0xb3, 0x82, 0x54 } };
  85.  
  86.         instance = NULL;
  87.         guid = defaultGUID;
  88.         name = "Application";
  89.         scale = 1.0f;
  90.         totalBackBuffers = 1;
  91.         HandleNetworkMessage = NULL;
  92.         StateSetup = NULL;
  93.         CreateMaterialResource = NULL;
  94.         spawnerPath = "./";
  95.     }
  96. };
  97.  
  98. //-----------------------------------------------------------------------------
  99. // Engine Class
  100. //-----------------------------------------------------------------------------
  101. class Engine
  102. {
  103. public:
  104.     Engine( EngineSetup *setup = NULL );
  105.     virtual ~Engine();
  106.  
  107.     void Run();
  108.  
  109.     HWND GetWindow();
  110.     void SetDeactiveFlag( bool deactive );
  111.  
  112.     float GetScale();
  113.     IDirect3DDevice9 *GetDevice();
  114.     D3DDISPLAYMODE *GetDisplayMode();
  115.     ID3DXSprite *GetSprite();
  116.  
  117.     void AddState( State *state, bool change = true );
  118.     void RemoveState( State *state );
  119.     void ChangeState( unsigned long id );
  120.     State *GetCurrentState();
  121.  
  122.     ResourceManager< Script > *GetScriptManager();
  123.     ResourceManager< Material > *GetMaterialManager();
  124.     ResourceManager< Mesh > *GetMeshManager();
  125.  
  126.     Input *GetInput();
  127.     Network *GetNetwork();
  128.     SoundSystem *GetSoundSystem();
  129.     SceneManager *GetSceneManager();
  130.  
  131. private:
  132.     bool m_loaded; // Indicates if the engine is loading.
  133.     HWND m_window; // Main window handle.
  134.     bool m_deactive; // Indicates if the application is active or not.
  135.  
  136.     EngineSetup *m_setup; // Copy of the engine setup structure.
  137.     IDirect3DDevice9 *m_device; // Direct3D device interface.
  138.     D3DDISPLAYMODE m_displayMode; // Display mode of the current Direct3D device.
  139.     ID3DXSprite *m_sprite; // Sprite interface for rendering 2D textured primitives.
  140.     unsigned char m_currentBackBuffer; // Keeps track of which back buffer is at the front of the swap chain.
  141.  
  142.     LinkedList< State > *m_states; // Linked list of states.
  143.     State *m_currentState; // Pointer to the current state.
  144.     bool m_stateChanged; // Indicates if the state changed in the current frame.
  145.  
  146.     ResourceManager< Script > *m_scriptManager; // Script manager.
  147.     ResourceManager< Material > *m_materialManager; // Material manager.
  148.     ResourceManager< Mesh > *m_meshManager; // Mesh manager.
  149.  
  150.     Input *m_input; // Input object.
  151.     Network *m_network; // Network object.
  152.     SoundSystem *m_soundSystem; // Sound system.
  153.     SceneManager *m_sceneManager; // Scene manager.
  154. };
  155.  
  156. //-----------------------------------------------------------------------------
  157. // Externals
  158. //-----------------------------------------------------------------------------
  159. extern Engine *g_engine;
  160.  
  161. #endif